package cn.tedu.movie.mapper;

import cn.tedu.movie.entity.OrderCancel;
import cn.tedu.movie.entity.OrderInsert;
import org.apache.ibatis.annotations.*;

@Mapper
public interface OrderMapper {
    @Insert("insert into `order` values(null,#{code},#{userId},#{totalPrice},"
            +"#{sessionId},#{statusId},#{createdDate},#{cancelDate})")
    int insertOrder(OrderInsert order);
    @Select("select LAST_INSERT_ID()")
    int lastInsert();
    @Select("select status_id from `order` where id =#{id}")
    Integer selectStatusById(int id);
    @Delete("delete from `order` where id = #{id}")
    int deleteOrderById(int id);
    @Select("SELECT m.name movie_name,c.name cinema_name,o.total_price total_price,\n" +
            "o.cancel_date cancel_date,o.code code,h.name hall_name,se.start_date start_date\n" +
            "FROM `movie` m,`order` o,session se,`hall` h,`cinema` c\n" +
            "WHERE se.id=o.session_id AND se.hall_id=h.id AND\n" +
            "se.movie_id=m.id AND h.cinema_id=c.id\n" +
            "and o.id=#{id}")
    @Result(column = "movie_name",property = "movieName")
    @Result(column = "cinema_name",property = "cinemaName")
    @Result(column = "total_price",property = "totalPrice")
    @Result(column = "cancel_date",property = "cancelDate")
    @Result(column = "start_date",property = "startTime")
    @Result(column = "hall_name",property = "hallName")
    OrderCancel orderCancel(Integer id);
    @Select("select id from `order` where code=#{code}")
    Integer selectByCode(String code);
    @Update("update `order` set status_id=1 where id=#{id}")
    int update(int id);
}
